import { ajax } from '@/utils'

const baseUrl = '/system/role'

export default {
  getRolePage(...args: IGetRolePageReq): Promise<IGetRolePageRes> {
    return ajax.post(`${baseUrl}/page`, args[0])
  },
  createRole(...args: ICreateRoleReq): IVoidRes {
    return ajax.post(`${baseUrl}/create`, args[0])
  },
  updateRole(...args: IUpdateRoleReq): IVoidRes {
    return ajax.put(`${baseUrl}/update/${args[0]}`, args[1])
  },
  deleteRole(...args: IDeleteReq): IVoidRes {
    return ajax.delete(`${baseUrl}/delete`, { data: args[0] })
  },
  exportRolePage(...args: IGetRolePageReq): IExportRes {
    return ajax.post(`${baseUrl}/export`, args[0], { responseType: 'blob' })
  },
  toggleRoleStatus(...args: IToggleRoleStatusReq): IVoidRes {
    return ajax.put(`${baseUrl}/toggleStatus/${args[0]}`)
  },
  getRoleAuthPage(...args: IGetRoleAuthPageReq): Promise<IGetRoleAuthPageRes> {
    return ajax.post(`${baseUrl}/roleAuth/page`, args[1], {
      params: { id: args[0] }
    })
  },
  cancelAuthUser(...args: ICancelAuthUserReq): IVoidRes {
    return ajax.put(`${baseUrl}/roleAuth/cancelAuthUser`, args[1], {
      params: { id: args[0] }
    })
  }
}
